package team.sun.sss.dao.extra;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import team.sun.sss.pojo.changework.ChangeWork;

import java.util.List;

@Mapper
@Repository
public interface ChangeWorkDao {

    //添加换班表
    @Insert("insert into change_work(change_apply_name,change_now_date,change_new_date,replace_name,change_reason,is_examine) " +
            "values(#{changeApplyName},#{changeNowDate},#{changeNewDate},#{replaceName},#{changeReason},#{isExamine})")
    int addChangeWork(ChangeWork changeWork);

    //查询换班表
    @Select("select * from change_work where is_examine='0'")
    List<ChangeWork> selectChangeWork();

    //根据id查询
    @Select("select * from change_work where change_id = #{id}")
    ChangeWork selectChangeWorkById(int id);

    //更改值班人员表（申请人）
    @Update("update extra_staff set sta_name=#{replaceName} where extra_time=#{changeNowDate} and sta_name=#{changeApplyName}")
    int updateExtraStaff1(ChangeWork changeWork);

    //更改值班人员表（被申请人）
    @Update("update extra_staff set sta_name=#{changeApplyName} where extra_time=#{changeNewDate} and sta_name=#{replaceName}")
    int updateExtraStaff2(ChangeWork changeWork);

    @Update("update change_work set is_examine='1' where change_id=#{changeId}")
    int updateChangeWork(ChangeWork changeWork);
}
